package com.hankol.community.adapter

import com.baselibrary.BaseConstant
import com.baselibrary.MessageBus
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.ARouterUtils
import com.baselibrary.utils.DoubleClickHelper
import com.baselibrary.utils.EventBusUtils.postSticky
import com.baselibrary.utils.EventBusUtils.sendNotify
import com.baselibrary.utils.SpanUtils
import com.baselibrary.view.VipHeardImgView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.community.R
import com.hankol.community.bean.FollowUsersBeanItem
import java.util.*


/**
 *@author:hanke
 *2022/3/30
 *desc:
 */
class FollowUsersAdapter : BaseQuickAdapter<FollowUsersBeanItem, BaseViewHolder>(R.layout.item_community_follow) {

    override fun convert(helper: BaseViewHolder, item: FollowUsersBeanItem) {
        helper.setText(R.id.tv_follow_name, SpanUtils.appendEllipsis(item.name, 4))
        if (item.isMore) {
            helper.getView<VipHeardImgView>(R.id.circle_follow_head).setDefault(R.drawable.icon_more_users, item.isFans == 1)
        } else {
            helper.getView<VipHeardImgView>(R.id.circle_follow_head).setData(item.icon, item.isFans == 1)
        }
        if (item.isMyself) {
            helper.setText(R.id.tv_follow_name, "分享生活")
            helper.setOnClickListener(R.id.ll_publish_dynamic) {
                sendNotify(MessageBus.msgid_publish_dynamic)
                postSticky(BaseConstant.loadPublishFOLLOW())
            }
        } else {
            helper.setOnClickListener(R.id.ll_publish_dynamic) {
                if (item.isMore) {
                    if (!DoubleClickHelper.isOnDoubleClick())
                        ARouterUtils.jump(ActivityRouter.MINE_CENTER.MINE_ATTENTIVE)
                } else {
                    if (!DoubleClickHelper.isOnDoubleClick())
                        goUserHomePage(item.uid)
                }
            }

        }
        helper.setVisible(R.id.iv_publish, item.isMyself)
        helper.setTextColor(R.id.tv_follow_name, mContext.resources.getColor(if (item.isMore) R.color.color_999999 else R.color.color_333333))
    }

    private fun goUserHomePage(id: Int) {
        val hashMap = HashMap<String, Any>()
        hashMap[BaseConstant.USER_ID] = id.toString()
        ARouterUtils.jump(ActivityRouter.MINE_CENTER.USER_INFO, hashMap)
    }
}